package sword_to_1;

import java.util.Arrays;

public class LeeCode_61 {
    public static void main(String[] args) {
//        System.out.println(isStraight(new int[]{0, 0, 1, 2, 5}));
        System.out.println(isStraight(new int[]{0, 0, 4, 5, 8}));
    }
    private static boolean isStraight(int[] nums) {
        Arrays.sort(nums);
        int count = nums[0] == 0 ? 1 : 0;
        int c = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == 0){
                count++;
                continue;
            }
            if (nums[i] == nums[i - 1]){
                return false;
            }
            if (nums[i - 1] != 0 && nums[i] - nums[i - 1] != 1){
                c += nums[i] - nums[i - 1] - 1;
            }
        }
        return count >= c;
    }
}
